package com.example.riceexambackend.dao.mapper;

import com.example.riceexambackend.dao.dataobject.QuestionTypeDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface QuestionTypeMapper {

    /**
     * 插入题型记录
     * @param questionTypeDO
     */
    @Insert("insert into t_question_type (question_name, question_score) values (#{questionName}, #{questionScore})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void insertQuestionType(QuestionTypeDO questionTypeDO);

    /**
     * 根据id查询题型
     * @param questionTypeId
     */
    @Select("select * from t_question_type where id = #{questionTypeId} and delete_flag = 0")
    QuestionTypeDO selectById(@Param("questionTypeId") Long questionTypeId);

    /**
     * 根据名称查询题型
     * @param questionTypeName
     */
    @Select("select * from t_question_type where question_name = #{questionTypeName}")
    QuestionTypeDO selectByName(@Param("questionTypeName") String questionTypeName);

    /**
     * 根据名称查询学分
     */
    @Select("select question_score from t_question_type where delete_flag = 0 and question_name = #{questionTypeName}")
    int selectScoreByName(@Param("questionTypeName") String questionTypeName);

    /**
     * 查询所有题型
     */
    @Select("select * from t_question_type where delete_flag = 0")
    List<QuestionTypeDO> selectList();

    /**
     * 根据id更新题型记录
     * @param questionTypeDO
     */
    @Update("update t_question_type set question_name = #{questionName},question_score = #{questionScore} where id = #{id}")
    void updateById(QuestionTypeDO questionTypeDO);

    /**
     * 根据id删除题型记录
     * @param questionTypeId
     */
    @Delete("update t_question_type set delete_flag = 1 where id = #{questionTypeId}")
    void deleteById(@Param("questionTypeId") Long questionTypeId);
}
